package ps.client.gui.dpsoverlay;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;

import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.ListCellRenderer;
import javax.swing.border.EmptyBorder;


@SuppressWarnings("serial")
public class DpsListCellRenderer extends JComponent implements ListCellRenderer {

    public static Color COLOR_BG_1 = Color.BLACK;
    public static Color COLOR_BG_2 = new Color(30, 30, 30);
    
    public static Color COLOR_FG_USER_NAME = new Color(100, 255, 150);
    public static Color COLOR_FG_DPS = Color.WHITE;
    
    public static Font FONT_USER_NAME = new Font("Arial", Font.BOLD, 12);
    
    JPanel contentPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 1, 0));
    
    JLabel userNameLabel = new JLabel();
    JLabel dpsLabel = new JLabel();
    
//    ImageIcon greenIcon = new ImageIcon(getClass().getResource("green.png"));
//    ImageIcon yellowIcon = new ImageIcon(getClass().getResource("yellow.png"));
//    ImageIcon redIcon = new ImageIcon(getClass().getResource("red.png"));
//    ImageIcon grayIcon = new ImageIcon(getClass().getResource("gray.png"));
//    ImageIcon fuchsiaIcon = new ImageIcon(getClass().getResource("fuchsia.png"));
//    ImageIcon blueIcon = new ImageIcon(getClass().getResource("blue.png"));
    
    public DpsListCellRenderer() {
        setLayout(new BorderLayout());
        add(contentPanel, BorderLayout.CENTER);
        
        contentPanel.setBorder(new EmptyBorder(2, 0, 0, 0));
        contentPanel.setPreferredSize(new Dimension(120, 14));
        contentPanel.setBackground(COLOR_BG_1);
        contentPanel.add(userNameLabel);
        contentPanel.add(dpsLabel);
        
        userNameLabel.setHorizontalAlignment(JLabel.LEFT);
        userNameLabel.setVerticalAlignment(JLabel.BOTTOM);
        userNameLabel.setForeground(COLOR_FG_USER_NAME);
        userNameLabel.setFont(FONT_USER_NAME);
        userNameLabel.setPreferredSize(new Dimension(68, 12));
        
        dpsLabel.setHorizontalAlignment(JLabel.RIGHT);
        dpsLabel.setVerticalAlignment(JLabel.BOTTOM);
        dpsLabel.setForeground(COLOR_FG_DPS);
        dpsLabel.setFont(FONT_USER_NAME);
        dpsLabel.setPreferredSize(new Dimension(50, 12));
    }

    @Override
    public Component getListCellRendererComponent(JList list, Object value,
            int index, boolean isSelected, boolean cellHasFocus) {
        
        if (value != null) {
            
            DpsListEntry entry = (DpsListEntry)value;
            
            contentPanel.setBackground(index % 2 == 1 ? COLOR_BG_1 : COLOR_BG_2);
            userNameLabel.setBackground(COLOR_BG_1);
            userNameLabel.setForeground(COLOR_FG_USER_NAME);
    
            userNameLabel.setText(entry.name);
            dpsLabel.setText(entry.dps);
            
        } else {
            return new JLabel();
        }
        
        return this;
    }

}
